<%!

  Copyright (c) Facebook, Inc. and its affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

%>template <class Protocol_>
uint32_t <%struct:name%>::serializedSize(Protocol_ const* prot_) const {
  uint32_t xfer = 0;
  xfer += prot_->serializedStructSize("<%struct:name%>");
<%#struct:fields%><%#field:type%>
<%#field:optional?%>
  if (this-><%^field:optionals?%><%^field:cpp_ref?%>__isset.<%/field:cpp_ref?%><%/field:optionals?%><%field:cpp_name%><%#field:optionals?%>.has_value()<%/field:optionals?%>) {
<%/field:optional?%>
<%#field:terse_writes?%><% > module_types_tcc/terse_if%><%/field:terse_writes?%>
<%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += prot_->serializedFieldSize("<%field:name%>", apache::thrift::protocol::<% > module_types_tcc/struct_type%>, <%field:key%>);
<%#field:cpp_ref?%>
<%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  if (this-><%field:cpp_name%>) {
<%/field:cpp_ref?%>
<%#type:resolves_to_base?%>
<%#type:resolves_to_integral?%>
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += ::apache::thrift::detail::pm::protocol_methods< <% > common/type_class%>, <% > types/type%>>::serializedSize<false>(*prot_, <%#field:cpp_ref?%>*<%/field:cpp_ref?%>this-><%field:cpp_name%><%#field:optionals?%>.value()<%/field:optionals?%>);
<%/type:resolves_to_integral?%>
<%^type:resolves_to_integral?%>
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += prot_->serializedSize<% > module_types_tcc/struct_field_type%>(this-><%field:cpp_name%><%#field:optionals?%>.value()<%/field:optionals?%><%type:cpp_indirection%>);
<%/type:resolves_to_integral?%>
<%/type:resolves_to_base?%>
<%#type:resolves_to_container_or_enum?%>
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += ::apache::thrift::detail::pm::protocol_methods< <% > common/type_class%>, <% > types/type%>>::serializedSize<false>(*prot_, <%#field:cpp_ref?%>*<%/field:cpp_ref?%>this-><%field:cpp_name%><%#field:optionals?%>.value()<%/field:optionals?%>);
<%/type:resolves_to_container_or_enum?%>
<%#type:struct?%>
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += ::apache::thrift::Cpp2Ops< <% > types/type%>>::serializedSize(prot_, <%^field:cpp_ref?%>&<%/field:cpp_ref?%>this-><%field:cpp_name%><%#field:optionals?%>.value()<%/field:optionals?%><%#field:cpp_ref?%>.get()<%/field:cpp_ref?%>);
<%/type:struct?%>
<%#field:cpp_ref?%>
<%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  }
<%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  else {
<%#type:resolves_to_container_or_enum?%>
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += prot_->serializedSize<% > module_types_tcc/struct_field_type%>Begin(<% > module_types_tcc/container_struct_type%>, 0);
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += prot_->serializedSize<% > module_types_tcc/struct_field_type%>End();
<%/type:resolves_to_container_or_enum?%>
<%#type:struct?%>
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%>  xfer += prot_->serializedStructSize("<%type:name%>");
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%>  xfer += prot_->serializedSizeStop();
<%/type:struct?%>
<%#field:optional?%>  <%/field:optional?%>  }
<%/field:cpp_ref?%>
<%#field:optional?%>
  }
<%/field:optional?%>
<%#field:terse_writes?%>
  }
<%/field:terse_writes?%>
<%/field:type%><%/struct:fields%>
  xfer += prot_->serializedSizeStop();
  return xfer;
}

template <class Protocol_>
uint32_t <%struct:name%>::serializedSizeZC(Protocol_ const* prot_) const {
  uint32_t xfer = 0;
  xfer += prot_->serializedStructSize("<%struct:name%>");
<%#struct:fields%><%#field:type%>
<%#field:optional?%>
  if (this-><%^field:optionals?%><%^field:cpp_ref?%>__isset.<%/field:cpp_ref?%><%/field:optionals?%><%field:cpp_name%><%#field:optionals?%>.has_value()<%/field:optionals?%>) {
<%/field:optional?%>
<%#field:terse_writes?%><% > module_types_tcc/terse_if%><%/field:terse_writes?%>
<%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += prot_->serializedFieldSize("<%field:name%>", apache::thrift::protocol::<% > module_types_tcc/struct_type%>, <%field:key%>);
<%#field:cpp_ref?%>
<%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  if (this-><%field:cpp_name%>) {
<%/field:cpp_ref?%>
<%#type:resolves_to_base?%>
<%#type:resolves_to_integral?%>
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += ::apache::thrift::detail::pm::protocol_methods< <% > common/type_class%>, <% > types/type%>>::serializedSize<false>(*prot_, <%#field:cpp_ref?%>*<%/field:cpp_ref?%>this-><%field:cpp_name%><%#field:optionals?%>.value()<%/field:optionals?%>);
<%/type:resolves_to_integral?%>
<%^type:resolves_to_integral?%>
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += prot_->serializedSize<%#type:binary?%>ZC<%/type:binary?%><% > module_types_tcc/struct_field_type%>(this-><%field:cpp_name%><%#field:optionals?%>.value()<%/field:optionals?%><%type:cpp_indirection%>);
<%/type:resolves_to_integral?%>
<%/type:resolves_to_base?%>
<%#type:resolves_to_container_or_enum?%>
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += ::apache::thrift::detail::pm::protocol_methods< <% > common/type_class%>, <% > types/type%>>::serializedSize<false>(*prot_, <%#field:cpp_ref?%>*<%/field:cpp_ref?%>this-><%field:cpp_name%><%#field:optionals?%>.value()<%/field:optionals?%>);
<%/type:resolves_to_container_or_enum?%>
<%#type:struct?%>
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += ::apache::thrift::Cpp2Ops< <% > types/type%>>::serializedSizeZC(prot_, <%^field:cpp_ref?%>&<%/field:cpp_ref?%>this-><%field:cpp_name%><%#field:optionals?%>.value()<%/field:optionals?%><%#field:cpp_ref?%>.get()<%/field:cpp_ref?%>);
<%/type:struct?%>
<%#field:cpp_ref?%>
<%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  }
<%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  else {
<%#type:resolves_to_container_or_enum?%>
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += prot_->serializedSize<% > module_types_tcc/struct_field_type%>Begin(<% > module_types_tcc/container_struct_type%>, 0);
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += prot_->serializedSize<% > module_types_tcc/struct_field_type%>End();
<%/type:resolves_to_container_or_enum?%>
<%#type:struct?%>
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%>  xfer += prot_->serializedStructSize("<%type:name%>");
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%>  xfer += prot_->serializedSizeStop();
<%/type:struct?%>
<%#field:optional?%>  <%/field:optional?%>  }
<%/field:cpp_ref?%>
<%#field:optional?%>
  }
<%/field:optional?%>
<%#field:terse_writes?%>
  }
<%/field:terse_writes?%>
<%/field:type%><%/struct:fields%>
  xfer += prot_->serializedSizeStop();
  return xfer;
}

template <class Protocol_>
uint32_t <%struct:name%>::write(Protocol_* prot_) const {
  uint32_t xfer = 0;
  xfer += prot_->writeStructBegin("<%struct:name%>");
<%#struct:fields%><%#field:type%>
<%#field:optional?%>
  if (this-><%^field:optionals?%><%^field:cpp_ref?%>__isset.<%/field:cpp_ref?%><%/field:optionals?%><%field:cpp_name%><%#field:optionals?%>.has_value()<%/field:optionals?%>) {
<%/field:optional?%>
<%#field:terse_writes?%><% > module_types_tcc/terse_if%><%/field:terse_writes?%>
<%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += prot_->writeFieldBegin("<%field:name%>", apache::thrift::protocol::<% > module_types_tcc/struct_type%>, <%field:key%>);
<%#field:cpp_ref?%>
<%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  if (this-><%field:cpp_name%>) {
<%/field:cpp_ref?%>
<%#type:resolves_to_base?%>
<%#type:resolves_to_integral?%>
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += ::apache::thrift::detail::pm::protocol_methods< <% > common/type_class%>, <% > types/type%>>::write(*prot_, <%#field:cpp_ref?%>*<%/field:cpp_ref?%>this-><%field:cpp_name%><%#field:optionals?%>.value()<%/field:optionals?%>);
<%/type:resolves_to_integral?%>
<%^type:resolves_to_integral?%>
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += prot_->write<% > module_types_tcc/struct_field_type%>(this-><%field:cpp_name%><%#field:optionals?%>.value()<%/field:optionals?%><%type:cpp_indirection%>);
<%/type:resolves_to_integral?%>
<%/type:resolves_to_base?%>
<%#type:resolves_to_container_or_enum?%>
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += ::apache::thrift::detail::pm::protocol_methods< <% > common/type_class%>, <% > types/type%>>::write(*prot_, <%#field:cpp_ref?%>*<%/field:cpp_ref?%>this-><%field:cpp_name%><%#field:optionals?%>.value()<%/field:optionals?%>);
<%/type:resolves_to_container_or_enum?%>
<%#type:struct?%>
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += ::apache::thrift::Cpp2Ops< <% > types/type%>>::write(prot_, <%^field:cpp_ref?%>&<%/field:cpp_ref?%>this-><%field:cpp_name%><%#field:optionals?%>.value()<%/field:optionals?%><%#field:cpp_ref?%>.get()<%/field:cpp_ref?%>);
<%/type:struct?%>
<%#field:cpp_ref?%>
<%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  }
<%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  else {
<%#type:resolves_to_container_or_enum?%>
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += prot_->write<% > module_types_tcc/struct_field_type%>Begin(<% > module_types_tcc/container_struct_type%>, 0);
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += prot_->write<% > module_types_tcc/struct_field_type%>End();
<%/type:resolves_to_container_or_enum?%>
<%#type:struct?%>
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%>  xfer += prot_->writeStructBegin("<%type:name%>");
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%>  xfer += prot_->writeStructEnd();
<%#field:cpp_ref?%>  <%/field:cpp_ref?%><%#field:optional?%>  <%/field:optional?%>  xfer += prot_->writeFieldStop();
<%/type:struct?%>
<%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  }
<%/field:cpp_ref?%>
<%#field:optional?%>  <%/field:optional?%><%#field:terse_writes?%>  <%/field:terse_writes?%>  xfer += prot_->writeFieldEnd();
<%#field:optional?%>
  }
<%/field:optional?%>
<%#field:terse_writes?%>
  }
<%/field:terse_writes?%>
<%/field:type%><%/struct:fields%>
  xfer += prot_->writeFieldStop();
  xfer += prot_->writeStructEnd();
  return xfer;
}
<%!
%>
